<!--企业角色管理 companyRoleManager-->
<template>
  <Layout>
    <Form ref="form1" :model="dataToQuery" :label-width="120">
      <Row v-show="!switchFlag" class="query-form">
        <Col span="8" v-if="!selectModal">
          <FormItem label="企业名称：" prop="order">
            <cascader-dom class="query-form-el" ref='queryOrgCascader' @setOrgInfo='setQueryCompanyName' :orgTree="true"
                          :setCurrentName="{label:dataToQuery.companyName,value:dataToQuery.companyId}"></cascader-dom>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="姓名：" >
            <Input  class=''  type='text' v-model='dataToQuery.userName'></Input>
          </FormItem>
        </Col>

        <Col span="8" >
          <Button @click="reset" class="ivu-btn-reset">重置</Button>
          <Button type="primary" class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
        </Col>
      </Row>
      <!--<Row class="query-form">-->
        <!--<Col span="24">-->
          <!--<Button size="large" class="ivu-btn-add" icon="md-add" @click="addInfo">新增</Button>-->
        <!--</Col>-->
      <!--</Row>-->
    </Form>
    <Table ref='table' :height="tableHeight" no-data-text="没有查询到相关数据!" @on-selection-change='getSelectRows'
           :loading='pageStatus.loading'
           border :columns="columns1" :data="dataTable">
    </Table>
    <Row style="margin-right:10px;">
      <Col span="24">
        <Page style="float: right" :total="pagedata.total" :page-size="pagedata.pageSize" @on-change="pageChange"
              @on-page-size-change="pageSizeChange" :page-size-opts="pageSizeArray" show-total show-sizer
              show-elevator/>
      </Col>
    </Row>
    <!--<user-manager-select @closeModel="closeModel"-->
                         <!--:company-id="currentUser.companyId"-->
                         <!--:userForSelectModal="userForSelectModal"-->
                         <!--:model="true" @getSelectModelData="getSelectModelData"/>-->

  </Layout>
</template>

<script>
import {Api} from '@/api/index.js'
import userManagerSelect from "@/views/base/authorityManager/userManagerSelect";
import pageCommonFunction from '@/components/pageCommonFunction.js'
import {sessionStorage} from "@/common/cacheUtils";

var cascaderDom = () => import('@/components/cascader-dom.vue');

export default {
    props: ['companyId','selectModal'],
  components: {
    cascaderDom,userManagerSelect
  },
  data() {
    return {
      ...this.createCommonDataField(),
      data:this.$route.query,
      userForSelectModal:false,
      columns: [
        {title: '序号', width: 70, fixed: 'left', align: 'center', render: this.indexColumnsRender},
        {key: 'userName', title: '姓名', align: 'center', width: 100},
        {key: 'loginId',  title: '登陆账号', align: 'center', width: 120},
          // {key: 'manageType', title: '管理员类型', align: 'center', width: 160},
        {key: 'twoLevelOrgname', title: '所属二级集团', align: 'center', minWidth: 160},
        {key: 'companyName', title: '所属单位', align: 'center', minWidth: 160},
        {key: 'orgName', title: '所属部门', align: 'center', width: 160},
          {
              title: '操作',
              key: 'action',
              fixed: 'right',
              width: 80,
              align: 'center',
              render: (h, params) => {
                  return h('div', [
                      h('A', {
                          props: {
                              type: 'primary',
                              size: 'small'
                          },
                          style: {
                              fontSize: '14px'
                          },
                          on: {
                              click: () => {
                                  this.$emit('getSelectModelData',params.row);
                                  this.$emit('closeModel');
                              }
                          }
                      }, '选择')
                  ]);
              }
          }
      ],
      currentUser:sessionStorage('userId').getObject('userId'),
      tableHeight: 10,
      uploadListVisible: [],
      uploadListPercent: [],
      dictMap: {},
      dataToView: {},
      uploadList: [],
      // api
      queryUrl: Api.queryCompanyRoleManager,
      deleteUrl: Api.deleteCompanyRoleManager,
      updateUrl: Api.updateCompanyRoleManager,
      saveUrl: Api.saveCompanyRoleManager,
    }
  },
    computed: {
        isResult() {
            // return this.$route.name === 'briefingList'//true事故简报  false事故事件月报
        },
        columns1() {
            const columns = [...this.columns];
            const columns1 = []
            columns.forEach(item => {
                if (this.selectModal) {
                    columns1.push(item)
                } else {
                    if (item.key !== 'action') {
                        columns1.push(item)
                    }
                }
            })
            return columns1
        },
    },
  async mounted() {
    this.setTableHeight();
    this.query();
  },
  methods: {
    ...pageCommonFunction,
    deleteData(params) {
      this.deleteDateAjax(params);
    },
    query() {
        if (this.companyId) {
            this.dataToQuery.companyId = this.companyId
        }
      this.dataToQuery.roleType = '1'
      this.queryAjax();
    },
    submit(data) {
      data.forEach(item =>{

        item["roleType"] = '1';
      })
      this.$http.post(this.saveUrl, data).then((res) => {
        if (res.data.status === 200) {
          this.$Message.success("保存成功");

        }else{
          this.$Message.error(res.data.msg);
        }
        this.query();
      }).catch(e => {
        this.$Message.error("数据获取失败")
      })

    },
    getSelectModelData(data){
      this.submit(data);
    },
    closeModel(){
      this.userForSelectModal = false;
    },
    addInfo() {
      this.userForSelectModal = true;
    },
    get_uuid() {
      let s = [];
      let hexDigits = "0123456789abcdef";
      for (let i = 0; i < 36; i++) {
        s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
      }
      s[14] = "4";
      s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
      s[8] = s[13] = s[18] = s[23] = "-";

      let uuid = s.join("");
      let reg = new RegExp("-", "g");
      let a = uuid.replace(reg, "");
      return a;
    },
    handleCancel() {
      this.dataToView = {};
      this.dialogShow = false;
      this.query();
    },
    formatDate(date, fmt) {
      if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
      }
      let o = {
        'M+': date.getMonth() + 1,
        'd+': date.getDate(),
        'h+': date.getHours(),
        'm+': date.getMinutes(),
        's+': date.getSeconds()
      };
      for (let k in o) {
        if (new RegExp(`(${k})`).test(fmt)) {
          let str = o[k] + '';
          fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : this.padLeftZero(str));
        }
      }
      return fmt;
    },
    padLeftZero(str) {
      return ('00' + str).substr(str.length);
    },
    createEmptyDataToAdd() {
      return {
        injuredNum: 0,
        deathNum: 0,
        economicLoss: 0,
        fileids: this.get_uuid(),
        belongOrgId: this.currentUser.twoLevelOrgId,
        belongOrgName: this.currentUser.twoLevelOrgName,
        eventOrgId: this.currentUser.companyId,
        eventOrgName: this.currentUser.companyName,
      }
    }
  },
  watch: {},
}
</script>

<style lang='css' scoped>
.rpt-form {
}

/deep/ .rpt-form .query-form-el {
  width: 100%;
}

/deep/ .rpt-form .ivu-form-item {
  margin-bottom: 24px;
}

</style>
